﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;

namespace GooNews.Controls
{
  public partial class AgiliTrainIconControl : UserControl
  {
    public AgiliTrainIconControl()
    {
      // Required to initialize variables
      InitializeComponent();
      MouseLeftButtonUp += (s, e) => new WebBrowserTask() { URL = "https://agilitrain.com" }.Show();
    }


    #region IconBrush (DependencyProperty)

    /// <summary>
    /// A description of the property.
    /// </summary>
    public Brush IconBrush
    {
      get { return (Brush)GetValue(IconBrushProperty); }
      set { SetValue(IconBrushProperty, value); }
    }
    public static readonly DependencyProperty IconBrushProperty =
        DependencyProperty.Register("IconBrush", typeof(Brush), typeof(AgiliTrainIconControl),
        new PropertyMetadata(null, new PropertyChangedCallback(OnIconBrushChanged)));

    private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      ((AgiliTrainIconControl)d).OnIconBrushChanged((Brush)e.NewValue);
    }

    protected virtual void OnIconBrushChanged(Brush newBrush)
    {
      foreach (var child in ((Panel)this.Content).Children)
      {
        var path = (Path)child;

        var scBrush = path.Fill as SolidColorBrush;
        if (scBrush != null &&  scBrush.Color != Color.FromArgb(0xFF, 0xF7, 0x94, 0x1D))
        {
          path.Fill = newBrush;
        }
      }
    }

    #endregion

  }
}